package com.gitee.wsl.mathematics.complex.quaternion.ext

import com.gitee.wsl.mathematics.complex.quaternion.Quaternion
import com.gitee.wsl.mathematics.number.compareTo
import com.gitee.wsl.mathematics.vector.ext.dot


/**
 * Returns the angle between this quaternion and [to]. This is the magnitude of the angle you would need to rotate by
 * to get from one to the other.
 *
 * Note: The magnitude of the floating-point error for this method is abnormally high, so methods such as
 * [isZeroApprox] will not work reliably.
 */
infix fun<T:Number> Quaternion<T, *>.angleTo(to: Quaternion<T, *>): T {
//    val d = dot(to)
//    return acos((d * d * 2 - 1).coerceIn(-1.0, 1.0))
    val dot = dot(to)
    return if (dot > one) zero else acos(min(abs(dot), one)) * 2.0f
}

